package com.bilicraft.plugin.kexue.jsonapi;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import com.alecgorge.minecraft.jsonapi.api.APIMethodName;

public class JaCmdGetSpellBooks extends JaCmd{

	@Override
	protected String doExec(APIMethodName arg0, Object[] arg1) {
		if(arg1.length < 1){
			return "player";
		}
		String url = (String) arg1[0];
		url = "plugins/MagicSpells/spellbooks/"+url.toLowerCase()+".txt";
		File file = new File(url);
		if(file.exists()){
			try{
				BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
				String s = br.readLine();
				String s0 = "root";
				while(s != null){
					s0 = s0 + "\r\n" + s;
					s = br.readLine();
				}
				return s0;
			}catch(Exception e){
				e.printStackTrace();
				return "error";
			}
		}else{
			return "error";
		}
	}

}
